package com.ktgj.service.controller;

import java.util.List;
import java.io.IOException;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ktgj.common.log.annotation.Log;
import com.ktgj.common.log.enums.BusinessType;
import com.ktgj.common.security.annotation.PreAuthorize;
import com.ktgj.service.domain.ViphallServiceInstructions;
import com.ktgj.service.service.IViphallServiceInstructionsService;
import com.ktgj.common.core.web.controller.BaseController;
import com.ktgj.common.core.web.domain.AjaxResult;
import com.ktgj.common.core.utils.poi.ExcelUtil;
import com.ktgj.common.core.web.page.TableDataInfo;

/**
 * 服务须知Controller
 * 
 * @author ruoyi
 * @date 2021-11-22
 */
@ControllerAdvice
@RestController
@RequestMapping("/instructions")
public class ViphallServiceInstructionsController extends BaseController
{
    @Autowired
    private IViphallServiceInstructionsService viphallServiceInstructionsService;

    /**
     * 查询服务须知列表
     */
    //@PreAuthorize(hasPermi = "service:instructions:list")
    @GetMapping("/list")
    public TableDataInfo list(ViphallServiceInstructions viphallServiceInstructions)
    {
        startPage();
        List<ViphallServiceInstructions> list = viphallServiceInstructionsService.selectViphallServiceInstructionsList(viphallServiceInstructions);
        return getDataTable(list);
    }

    /**
     * 导出服务须知列表
     */
    //@PreAuthorize(hasPermi = "service:instructions:export")
    @Log(title = "服务须知", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ViphallServiceInstructions viphallServiceInstructions) throws IOException
    {
        List<ViphallServiceInstructions> list = viphallServiceInstructionsService.selectViphallServiceInstructionsList(viphallServiceInstructions);
        ExcelUtil<ViphallServiceInstructions> util = new ExcelUtil<ViphallServiceInstructions>(ViphallServiceInstructions.class);
        util.exportExcel(response, list, "服务须知数据");
    }

    /**
     * 获取服务须知详细信息
     */
    //@PreAuthorize(hasPermi = "service:instructions:query")
    @GetMapping(value = "/{serviceId}")
    public AjaxResult getInfo(@PathVariable("serviceId") Long serviceId)
    {
        return AjaxResult.success(viphallServiceInstructionsService.selectViphallServiceInstructionsById(serviceId));
    }

    /**
     * 新增服务须知
     */
    //@PreAuthorize(hasPermi = "service:instructions:add")
    @Log(title = "服务须知", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody ViphallServiceInstructions viphallServiceInstructions)
    {
        return toAjax(viphallServiceInstructionsService.insertViphallServiceInstructions(viphallServiceInstructions));
    }

    /**
     * 修改服务须知
     */
    //@PreAuthorize(hasPermi = "service:instructions:edit")
    @Log(title = "服务须知", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public AjaxResult edit(@RequestBody ViphallServiceInstructions viphallServiceInstructions)
    {
        return toAjax(viphallServiceInstructionsService.updateViphallServiceInstructions(viphallServiceInstructions));
    }

    /**
     * 删除服务须知
     */
    //@PreAuthorize(hasPermi = "service:instructions:remove")
    @Log(title = "服务须知", businessType = BusinessType.DELETE)
	@PostMapping("/remove")
    public AjaxResult remove(@RequestBody Map<String, Long> map)
    {
        return toAjax(viphallServiceInstructionsService.deleteViphallServiceInstructionsByIds(new Long[]{map.get("serviceId")}));
    }

    /**
     * 查询服务须知列表
     */
    @PostMapping("/selectInstructions")
    public AjaxResult selectInstructions(@RequestBody Map<String, Long> map) {
        ViphallServiceInstructions viphallServiceInstructions = new ViphallServiceInstructions();
        viphallServiceInstructions.setViphallId(map.get("viphallId"));
        return AjaxResult.success(viphallServiceInstructionsService.selectViphallServiceInstructionsList(viphallServiceInstructions));
    }
}
